/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package east2west.action;

import east2west.dao.HotelDAO;
import east2west.dto.HotelDTO;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author Admin
 */
public class AdminHotelAction extends DispatchAction {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
    private static final String TRUE = "true";
    private static final String ERR = "err";

   
    public ActionForward listHotel(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        HotelDAO dao = new HotelDAO();
        ArrayList<HotelDTO> list = dao.readByAll();
        request.setAttribute("list", list);
        request.setAttribute("page", "hotel.page");
        return mapping.findForward(SUCCESS);
    }



//    public ActionForward insertHotel(ActionMapping mapping, ActionForm form,
//            HttpServletRequest request, HttpServletResponse response)
//            throws Exception {
//        HotelDTO dto = new HotelDTO();
//        HotelDAO dao = new HotelDAO();
//        dto.setHotelName(request.getParameter("frhotelname"));
//        dto.setEmail(request.getParameter("frhotelemail"));
//        dto.setWebsite(request.getParameter("frhotelweb"));
//        dto.setImagesUrl(request.getParameter("frhotelimage"));
//        dto.setRate(Integer.parseInt(request.getParameter("frhotelrate")));
//        dto.setAddress(request.getParameter("frhoteladd"));
//        dto.setPhone(request.getParameter("frhotelphone"));
//        dto.setCity(request.getParameter("frhotelcity"));
//        dto.setDescription(request.getParameter("frhoteldes"));
//        //dto.setIsDeleted(request.getParameter("isDeleted"));
//        if (dao.create(dto)) {
//            return mapping.findForward(TRUE);
//        }
//        else
//        {
//        return mapping.findForward(ERR);
//        }
//    }

//    public ActionForward insertHotel(ActionMapping mapping, ActionForm form,
//            HttpServletRequest request, HttpServletResponse response)
//            throws Exception {
//        HotelDTO dto = new HotelDTO();
//        HotelDAO dao = new HotelDAO();
//        dto.setHotelName(request.getParameter("frhotelname"));
//        dto.setEmail(request.getParameter("frhotelemail"));
//        dto.setWebsite(request.getParameter("frhotelweb"));
//        dto.setImagesUrl(request.getParameter("frhotelimage"));
//        dto.setRate(Integer.parseInt(request.getParameter("frhotelrate")));
//        dto.setAddress(request.getParameter("frhoteladd"));
//        dto.setPhone(request.getParameter("frhotelphone"));
//        dto.setCity(request.getParameter("frhotelcity"));
//        dto.setDescription(request.getParameter("frhoteldes"));
//        //dto.setIsDeleted(request.getParameter("isDeleted"));
//       if(dao.create(dto)>0){
//            return mapping.findForward(TRUE);
//        }
//        else
//        {
//        return mapping.findForward(ERR);
//        }
//    }



    public ActionForward deleteHotel(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int id = Integer.parseInt(request.getParameter("frhotelidd"));
        HotelDAO dao = new HotelDAO();
        if (dao.delete(id)) {
            return mapping.findForward(TRUE);
        } else {
            return mapping.findForward(ERR);
        }

    }

    public ActionForward editHotel(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        // int id = Integer.parseInt(request.getParameter("id"));
        HotelDAO dao = new HotelDAO();
        HotelDTO dto = new HotelDTO();
        dto.setHotelId(Integer.parseInt(request.getParameter("frhotelidd")));
        dto.setHotelName(request.getParameter("frhotelname"));
        dto.setEmail(request.getParameter("frhotelemail"));
        dto.setWebsite(request.getParameter("frhotelweb"));
        dto.setImagesUrl(request.getParameter("frhotelimage"));
        dto.setRate(Integer.parseInt(request.getParameter("frhotelrate")));
        dto.setAddress(request.getParameter("frhoteladd"));
        dto.setPhone(request.getParameter("frhotelphone"));
        dto.setCity(request.getParameter("frhotelcity"));
        dto.setDescription(request.getParameter("frhoteldes"));
        if (dao.update(dto)) {
            return mapping.findForward(TRUE);
        } else {
            return mapping.findForward(ERR);
        }
    }
}
